package com.CGFrame.struts.bean.unit;

import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;

import com.CGFrame.struts.POJOs.Element;
import com.CGFrame.struts.POJOs.Elementgroup;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;
import com.CGFrame.tools.FileFilter;
import com.config.GenericConfig;

public class ElementBean {
	Element element;
	
	private String filebase = GenericConfig.getInstance().getFileBase();
	 
	public ElementBean()
	{
		
	}
	public ElementBean(int elementId)
	{
		ProjectOperate pop = ProjectOperateFactory.getprojectOperate();
		element =(Element)pop.UniqueQuery("Element", "elementId,"+elementId);
	}
	public int getPlanHours()
	{
		Date dat_StartTime = element.getPlanStartTime();
		Date dat_EndTime   = element.getPlanEndTime();
		int planHours = (dat_EndTime.compareTo(dat_StartTime)+1)*8;//Ԫ�ؼƻ���ʱ����ÿ��8Сʱ����
		return planHours;
	}
	public int getMakeHours()
	{
		Iterator ite_Makes = element.getMakes().iterator();
		return 20;
	}
	public int getActualHours()
	{
		Date currentDate = new Date();
		Date startDate = element.getPlanStartTime();
		int actualHours = (currentDate.compareTo(startDate))*8;
		return actualHours;
	}
	
	public  String getFilePathforElement(int Flag)
	{
//		path="CCTV/Project/scenes/Assets/Production/Characters/ShiTong/";   
//		path="CCTV/Project/scenes/Episodes/Episode001/Production/Shot/Shot002/";
		
		StringBuffer unitPath = new StringBuffer();
			unitPath =(StringBuffer)FilePathGenerator.getFilePath(this.getElementId(),"Element").get(0);
		
		if ( FilePathGenerator.MediaFile == Flag)
		{
			unitPath.append("Media/Working/");
		}
		else if ( FilePathGenerator.FinishedMediaFile == Flag)
		{
			unitPath.append("Media/Approved/");
		}
		
		return unitPath.toString();
	}
	
	public LinkedList getElementGroupName(){
		LinkedList<String> list=new LinkedList<String>();
		Elementgroup elementgroup=element.getElementgroup();
		while(elementgroup!=null){
			list.addFirst(elementgroup.getElementGroupName());
			elementgroup=elementgroup.getElementgroup();
		}
		return list;
		}
	
	public String getElementName(){
		return element.getElementName();
	}
	public String getProjectName()
	{
		return element.getElementgroup().getProject().getProjectName();
	}
	public int getElementId(){
		return element.getElementId();
	}
	public Element getElement() {
		return element;
	}
	public String getProPath()
	{
		String path = FilePathGenerator.getPreProductionPath(this.element.getElementId(),"Element").toString();
		 String abpath = filebase + path;
		 if ( FileFilter.makeFilePath(abpath))
		 {
			 return path;
		 }
		 else
		 {
			 return null;
		 }
	}
	public String getAbProPath()
	{
		String path = getProPath();
		if (path!=null) return filebase + path;
		else return null;
	}
}
